<template>
  <div>
    <el-table :data="inquiryList" style="width: 100%; margin-top: 20px;">
      <el-table-column prop="id" label="ID" width="60"/>
      <el-table-column prop="userName" label="用户"/>
      <el-table-column prop="content" label="咨询内容"/>
      <el-table-column prop="reply" label="医生回复"/>
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button size="small" @click="replyInquiry(scope.row)">回复</el-button>
          <el-button size="small" type="danger" @click="deleteInquiry(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog v-model="showReply" title="回复问诊">
      <el-input v-model="replyContent" placeholder="请输入回复内容" />
      <template #footer>
        <el-button @click="showReply = false">取消</el-button>
        <el-button type="primary" @click="saveReply">保存</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { getInquiryListApi, replyInquiryApi, deleteInquiryApi } from '../api/inquiry'
const inquiryList = ref([])
const showReply = ref(false)
const replyContent = ref('')
const currentRow = ref(null)
const loadInquiries = async () => { inquiryList.value = await getInquiryListApi() }
const replyInquiry = (row) => { currentRow.value = row; replyContent.value = ''; showReply.value = true }
const saveReply = async () => {
  await replyInquiryApi({ id: currentRow.value.id, reply: replyContent.value })
  showReply.value = false
  loadInquiries()
}
const deleteInquiry = async (id) => { await deleteInquiryApi(id); loadInquiries() }
onMounted(loadInquiries)
</script> 